# Contributor: Bart Ribbers <bribbers@disroot.org>
# Maintainer: Bart Ribbers <bribbers@disroot.org>
pkgname=maplibre-native-qt
pkgver=3.0.0
pkgrel=0
pkgdesc="Open-source alternative to Mapbox GL Native"
url="https://maplibre.org/"
arch="all"
license="BSD-2-Clause"
# It searches for Qt6 dependencies but it actually uses Qt5
makedepends="
	cmake
	icu-dev
	qt5-qtbase-dev
	qt5-qtlocation-dev
	rapidjson-dev
	samurai
	"
subpackages="$pkgname-dev"
source="https://dev.alpinelinux.org/archive/maplibre-native-qt/maplibre-native-qt-$pkgver.tar.xz"
options="!check" # No tests
builddir="$srcdir/maplibre-native-qt"

provides="maplibre-gl-native=$pkgver-r$pkgrel"
replaces="maplibre-gl-native"

_disturl="dev.alpinelinux.org:/archive/$pkgname/"

snapshot() {
	clean
	deps
	mkdir -p "$srcdir" && cd "$srcdir"
	git clone https://github.com/maplibre/maplibre-native-qt -b v$pkgver --recursive
	tar cv maplibre-native-qt | xz -T0 -9 -vv - > $SRCDEST/$pkgname-$pkgver.tar.xz
	rsync --progress -La $SRCDEST/$pkgname-$pkgver.tar.xz $_disturl
}

prepare() {
	default_prepare

	# We prefer to build with our system version
	rm -r vendor/maplibre-native/vendor/mapbox-base/extras/rapidjson
}

build() {
	cmake -B build -G Ninja \
		-DCMAKE_BUILD_TYPE=None \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_SHARED_LIBS=TRUE \
		-DQT_VERSION_MAJOR=5
	cmake --build build
}

package() {
	DESTDIR="$pkgdir" cmake --install build
}

sha512sums="
c71b480900f7a54ac5dc902492c7256b89063770c0bdaddead23e2d8d0442171507f75aa109c8903306f35b5c52a7a71a72570458c2b949147670a1bcb265006  maplibre-native-qt-3.0.0.tar.xz
"
